<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>服务类型增加或修改页面</title>
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
    <script src="../../../../res/js/jquery-3.1.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script type="text/javascript" src="../../res/js/login_common.js"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js"></script>
    <style>
        #btn:hover{
            background: #33aba0;
            cursor: pointer;
        }
        #btn{
            background: #009688;
            color: white;
            width: 100px;
            height: 36px;
            border: 0;
        }
    </style>
    <script>
        $.ajaxSetup({
            async: false
        });
    </script>
</head>
<body>
<!--<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加新闻</legend>
</fieldset>-->

<form class="layui-form" lay-filter="example" action="" id="formDId"  method="post" enctype="multipart/form-data">
    <input type="hidden" id="syId" name="syId">
    <div class="layui-form-item">
        <label class="layui-form-label">类型名称:</label>
        <div class="layui-inline">
            <input type="text" name="syName" style="width: 400px" id="syName"  lay-verify="required" placeholder="请输入类型名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-bg-red">重置按钮</button>
        </div>
    </div>
</form>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    var form=null;
    layui.use('form', function() {
        form = layui.form;
        //监听提交
        form.on('submit(demo1)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            var formData = new FormData(document.getElementById("formDId"));
            var loadIndex =layer.load();
            var url = "../../../../dkm.dkmproject/servicetypeTb/addorUpdate";
            $.ajax({
                url: url,
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (obj) {
                    if (obj.num >0) {
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000 //1秒关闭(如果不配置默认三秒)
                        }, function () {
                            layer.close(loadIndex);
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            parent.layui.table.reload("test");
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面

                            //parent.location.reload();
                        });
                        return false;
                    }else{
                        layer.msg(obj.msg);
                        layer.close(loadIndex);
                        return false;
                    }
                },
                error: function (e) {
                    layer.msg("错误！！");
                }
            });
            return false;
        });
    })
    //修改操作
    var ide = getQueryString("id");

    if(ide) {
        findById();//修改页面的赋值
        var str=$("#nSmallfileone").val();
        if(str.length>1){
            $("#ts").text(str.substring(0,13)+"。。。。。 ."+str.match(/\.([^\.]+)$/)[1]);
            $("#ts").prop("href",getRootPathTwo()+str);
        }
    }
    //修改页面的赋值
    function findById(){
        var id=getQueryString("id");
        var url="../../../../dkm.dkmproject/servicetypeTb/findById";
        var data={syId:id};
        $.post(url,data,function(obj){
            $("#syId").val(obj.syId);
            $("#syName").val(obj.syName);
        },"json");

    }
</script>


</body>
</html>